package com.sk.ccflower.server.match.xmlrpc;

import java.util.Vector;

import org.apache.log4j.Logger;

import com.sk.ccflower.lib.commonBeans.XmlRpcResultBean;
import com.sk.ccflower.lib.commonUtils.PhotoUtil;
import com.sk.ccflower.lib.define.Consts;
import com.sk.ccflower.lib.mtBeans.MatchingProfileBean;
import com.sk.ccflower.server.common.xmlRpcManager.BaseXmlRpcWorker;
import com.sk.ccflower.server.lib.dbUtils.ConnectionPoolManager;
import com.sk.ccflower.server.lib.dbUtils.DBConnection;
import com.sk.ccflower.server.lib.dbUtils.qry.MfMatchQry;

public class MatchingCenterXmlRpc extends BaseXmlRpcWorker {
	
	private Logger m_log;
	
	public MatchingCenterXmlRpc(ConnectionPoolManager dbcp) {
		super(dbcp);
		
		this.m_log = Logger.getLogger( getClass() );
		
		this.m_log.debug( "MatchingCenterXmlRpc Constructor called!" );
	}
	
	@Override
	protected void finalize() throws Throwable {
		super.finalize();
		
		this.m_log.debug( "MatchingCenterXmlRpc finalize() called!" );
	}
	
	public XmlRpcResultBean matchingProfileWork(String email) throws Exception {
		DBConnection dbconn = null;
		XmlRpcResultBean retBean = new XmlRpcResultBean();
		
		try {
			retBean.resultList = new Vector<Object>();
			
			dbconn = new DBConnection( super.mConnectionPool.getConnection() );
			MfMatchQry qry = new MfMatchQry(dbconn);
			qry.select( email );
			
			for ( int i=0; i<qry.size(); i++ ) {
				MatchingProfileBean bean = (MatchingProfileBean) qry.m_arr.get(i);
				
				bean.pic_e = PhotoUtil.getDefaultPhoto( bean.email, Consts.PHOTO_TYPE.EYE );
				bean.pic_n = PhotoUtil.getDefaultPhoto( bean.email, Consts.PHOTO_TYPE.NOSE );
				bean.pic_m = PhotoUtil.getDefaultPhoto( bean.email, Consts.PHOTO_TYPE.MOUTH );
				
				retBean.resultList.add( bean );
			}
		} catch ( Exception e ) {
			retBean.resultCode = XmlRpcResultBean.XML_RPC_RESULT_FAILURE;
			
			this.m_log.error( e );
			e.printStackTrace();
			throw e;
		} finally {
			if ( null != dbconn )	dbconn.close();
		}
		
		return retBean;
	}
	
}
